home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / umich / network / ka9q / ka9q_src.arc / TIMER.H < prev    next >
C/C++ Source or Header  |  1988-07-28  |  1KB  |  29 lines

  1. /* Software timers
  2.  * There is one of these structures for each simulated timer.
  3.  * Whenever the timer is running, it is on a doubly-linked list
  4.  * pointed to by "timers" so that the (hardware) timer interrupt
  5.  * can quickly run through the list and change counts and states.
  6.  * Stopping a timer or letting it expire causes it to be removed
  7.  * from the list; starting a timer puts it on the list.
  8.  */
  9. struct timer {
  10.     struct timer *next;    /* Doubly-linked-list pointers */
  11.     struct timer *prev;
  12.     int16 start;        /* Period of counter (load value) */
  13.     int16 count;        /* Ticks to go until expiration */
  14.     void (*func)();        /* Function to call at expiration */
  15.     char *arg;        /* Arg to pass function */
  16.     char state;        /* Timer state */
  17. #define    TIMER_STOP    0
  18. #define    TIMER_RUN    1
  19. #define    TIMER_EXPIRE    2
  20. };
  21. #define    NULLTIMER    (struct timer *)0
  22. #define    MAX_TIME    (int16)65535    /* Max short integer */
  23. #define    MSPTICK        1000        /* Milliseconds per tick */
  24. /* Useful user macros that hide the timer structure internals */
  25. #define    set_timer(t,x)    (((t)->start) = (x)/MSPTICK)
  26. #define    dur_timer(t)    ((t)->start)
  27. #define    read_timer(t)    ((t)->count)
  28. #define    run_timer(t)    ((t)->state == TIMER_RUN)
  29.